package com.empresa.iflex.core;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.empresa.iflex.R;


public class iFlex extends Activity {	
	/* Chamada quando o botão Menu é apertado */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
       MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.menu, menu);
          return true;
    }
    
    
    /* Chamad quando uma opção do Menu é selecionada */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
      // Captura o menu selecionado
       switch (item.getItemId()) {
          case R.id.about:
             mAbout();
             return true;
          case R.id.sair:
             finish();
             return true;
          default:
             return super.onOptionsItemSelected(item);
       }
    }
    
    
    /* Opção "About" do Menu */
    private void mAbout(){  
    	Context mContext = getApplicationContext();
    	LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    	View layoutmenu = inflater.inflate(R.layout.about,
                (ViewGroup) findViewById(R.id.layoutmenu));

    	AlertDialog.Builder builder = new AlertDialog.Builder(this);  
    	builder.setIcon(R.drawable.f);
    	builder.setTitle("iFlex");
	    builder.setView(layoutmenu)
	    	.setCancelable(false)
	    	.setPositiveButton("Ok", new DialogInterface.OnClickListener(){ 
	    		public void onClick(DialogInterface dialog, int id){  
	    			dialog.cancel();
	    	    }  
	    }); 
    	AlertDialog alert = builder.create();  
    	alert.show(); 
    	
    } 
	
    
	/* Chamada quando o programa é inicializado */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      
        CarregaTelaInicial();
    }
    
    
    /* Carrega a tela principal do programa */
    public void CarregaTelaInicial(){
    	
        setContentView(R.layout.main);
        findViewById(R.id.bComp).setOnClickListener(mComp);
        findViewById(R.id.bMed).setOnClickListener(mMed);
        findViewById(R.id.bAdd).setOnClickListener(mAdd);
        findViewById(R.id.bVer).setOnClickListener(mVer);
        
        /* Linka o logo ao site */
        ImageView flex = (ImageView) findViewById(R.id.flex);
        flex.setOnClickListener( new View.OnClickListener()
        {
			public void onClick(View v)
			{
				Uri uri = Uri.parse( "https://market.android.com" );
				startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
			}
        });
    }
    
    
    /* Chamada quando a funcao de comparacao de combustiveis é solicitada */
    public final Button.OnClickListener mComp = new Button.OnClickListener() {
        public void onClick(View v) {
        	Intent myIntent = new Intent(iFlex.this, Compara.class);
      	  	iFlex.this.startActivity(myIntent);
        }
    };   
    
    
    /* Chamada quando a funcao de calculo de media é solicitada */
    public final Button.OnClickListener mMed = new Button.OnClickListener() {
        public void onClick(View v) {
        	Intent myIntent = new Intent(iFlex.this, Media.class);
      	  	iFlex.this.startActivity(myIntent);      	  	
        }
    }; 
    
        
    /* Chamada quando a adicao de dados as estatisticas é solicitada */
    public final Button.OnClickListener mAdd = new Button.OnClickListener() {
        public void onClick(View v) {
        	Intent myIntent = new Intent(iFlex.this, Add.class);
      	  	iFlex.this.startActivity(myIntent); 
        }
    };
    
    
    /* Chamada quando a visualizacao das estatisticas é solicitada */
    public final Button.OnClickListener mVer = new Button.OnClickListener() {
        public void onClick(View v) {
        	Intent myIntent = new Intent(iFlex.this, Tab.class);
      	  	iFlex.this.startActivity(myIntent); 
        }
    };
    
}